import { useState } from 'react';
import React from 'react';


const Compare = () => {
    const [favor, setFavor] = useState(0);
    const [disag, setDisag] = useState(0);
    const [vate, setVate] = useState(0);

    const add1 = () => {
        setFavor(favor + 1);
        setVate((favor + 1) / (favor + 1 + disag))
    }
    const add2 = () => {
        setDisag(disag + 1)
        setVate(favor / (favor + 1 + disag))

    }



    return (
        <div>
            <div>支持:{favor}</div>
            <div>反对:{disag}</div>
            <div>支持率:{(vate * 100).toFixed(2) + "%"}</div>
            <button onClick={add1}>支持</button>
            <button onClick={add2}>反对</button>
            {/* <button onClick={}>弃权</button> */}
        </div>
    )
}
export default Compare;


